package com.webmeeting.chat.wordchat.servlets;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.myframework.utils.jsutil.JavascriptUtil;

public class RetrieveUserServlet extends HttpServlet {

	private static final long	serialVersionUID	= 1L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Map<String, Object> responseMap = new HashMap<String, Object>();
		
		responseMap.put("user", ((HttpSession) request.getSession()).getAttribute("user"));
		
		response.setContentType("application/json");
		String serializedRespMap = JavascriptUtil.serializeToJS(responseMap);
		response.getWriter().write(serializedRespMap);
		response.flushBuffer();
	}

}
